package com.java.multipledatasource.thread;

import java.util.concurrent.*;

/**
 * @author hu
 * @version 1.0
 * @date 2021/1/18 0018 上午 8:05
 * @description
 */
public class MyFuture {
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newFixedThreadPool(5);
        Future<Integer> future = threadPool.submit(() -> {
           Thread.sleep(5000);
            return 100;
        }); // 异步
        System.out.println(1);
        try {
            System.out.println(future.get());// 阻塞
            System.out.println(2);

        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        threadPool.shutdown();
    }
}
